package com.liao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liao.bean.Spay;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.dao.SpayDao;
import com.liao.service.SpayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpayServiceImpl implements SpayService {

    @Autowired
    private SpayDao spayDao;

    @Override
    public PageResult<Spay> querySpayListByPage(Integer currentPage, Integer pageSize, String accountName) throws Exception {
        PageHelper.startPage(currentPage, pageSize);
        List<Spay> spayList = spayDao.selectSpayListByPage(accountName);
        PageInfo pageInfo = new PageInfo(spayList);
        return new PageResult<>(0, Msg.SPAY_QUERY_SUCCESS, pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public void deleteSpayById(String payId) throws Exception {
        spayDao.deleteSpayById(payId);
    }

    @Override
    public void addSpay(String payType, String payAccount, String accountName, String operater, String payMoney) throws Exception {
        Spay spay = new Spay();

        spay.setPayType(payType);
        spay.setPayAccount(payAccount);
        spay.setAccountName(accountName);
        spay.setOperater(operater);
        spay.setPayMoney(payMoney);

        spayDao.addSpay(spay);
    }

    @Override
    public void updateSpay(Integer payId, String payType, String payAccount, String accountName, String operater, String payMoney) throws Exception {
        Spay spay = new Spay();

        spay.setPayId(payId);
        spay.setPayType(payType);
        spay.setPayAccount(payAccount);
        spay.setAccountName(accountName);
        spay.setOperater(operater);
        spay.setPayMoney(payMoney);

        spayDao.updateSpay(spay);
    }
}
